<%@ include file="abrirEvento.jsp" %>
<%
    String endereco = objEvento.getString("endereco") != null ? objEvento.getString("endereco") : "";
    String menssagem = objEvento.getString("menssagem") != null ? objEvento.getString("menssagem") : "";
    String sqlEventoLista = "SELECT  EVENTO.ENDERECO , EVENTO.MENSSAGEM FROM EVENTO WHERE  ID <>  "+objEvento.getId() ;
    ResultSet crsEventoLista = new ControllerRosena().execultarQueryReturResultSet(sqlEventoLista);
    String zoom = request.getParameter("zoom") != null ? request.getParameter("zoom") : "7";
%>
<html>
<head>
    <title>Sile</title>

    <style type="text/css">

        #mapa{
            width:100%;
            height:100%;
        }

    </style>



    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script type="text/javascript" >

        var map = null;
        var geocoder = new google.maps.Geocoder();
        var bounds = new google.maps.LatLngBounds();

        function carregar(){
            var latlng = new google.maps.LatLng(0,0);

    		var myOptions = {
                zoom: <%=zoom%>,
                mapTypeId: google.maps.MapTypeId.ROADMAP
    		};

			//criando o mapa
    		map = new google.maps.Map(document.getElementById("mapa"), myOptions);
                geocoder.geocode( { 'address':'<%=endereco%>'}, function(results,status) {
                    if (status == google.maps.GeocoderStatus.OK){
                        for( var i=0; i<results.length; i++ ){
                            bounds.extend( results[i].geometry.location );
                            map.setCenter(new google.maps.LatLng( bounds.getCenter().lat(),bounds.getCenter().lng()),7);

                            var local = new google.maps.LatLng(bounds.getCenter().lat(),bounds.getCenter().lng());
                            marcadorLocal = new google.maps.Marker({
                                position: local,
                                map: map,
                                title:""
                            });


                            var infowindow = new google.maps.InfoWindow({
                                content: "<%=menssagem%>"
                            });

                            infowindow.open(map,marcadorLocal);

                            google.maps.event.addListener(marcadorLocal, 'click', function(event) {
                                infowindow.open(map,marcadorLocal);
                            });
                        }
                    }
                });

                <% while(crsEventoLista.next() ){%>
                     geocoder.geocode( { 'address':'<%=crsEventoLista.getString("endereco")%>' }, function(results,status) {
                        if (status == google.maps.GeocoderStatus.OK){
                            for( var i=0; i<results.length; i++ ){
                                bounds.extend( results[i].geometry.location );
                                var local = new google.maps.LatLng(bounds.getCenter().lat(),bounds.getCenter().lng());
                                marcadorLocal = new google.maps.Marker({
                                    position: local,
                                    map: map,
                                    title:"aqui e o titulo"
                                });

                                var infowindow = new google.maps.InfoWindow({
                                    content: "<%=crsEventoLista.getString("MENSSAGEM").replace("@quebraLinha@","<br>")%>"
                                });

                                google.maps.event.addListener(marcadorLocal, 'click', function(event) {
                                    infowindow.open(map,marcadorLocal);
                                });
                            }
                        }
                    });
                 <%}%>
             }
    </script>
</head>
<body onload="carregar();">
<div id="mapa"></div>
</body>
</html>